<?php 
$weekarr = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
$week = $weekarr[date("w")];
?>
<div id="candidate" class="indexcontentdiv">
    <div class="positiondiv">
        <table>
            <tr>
                <td class="td-left">
                    <img src="<?=base_url()?>resource/img/home_ico.png" width="21" height="17">
                    <?=$this->lang->line("Report")?> > <?=$this->lang->line("Sales Completion Summary")?>
                </td>
                <td class="td-right">
                    <img src="<?=base_url()?>resource/img/menu2.png" width="27" height="24"><?=$this->lang->line("TodayIS")?> <?=$week?>,<?=date('M d,Y')?>
                </td>
            </tr>
        </table>
    </div>
    <div class="list-div" style="margin-top:0px;">
        <?php echo form_open('reminder/summary'); ?>
        <table class="top-table" style="margin:10px 0px 10px 20px;">
            <tr>
                <td style="height:50px;">
                    <input type="hidden" value="<?=$searchData['ordername']?>" name="ordername" id="ordername" />
                    <label><?=$this->lang->line("Search Status")?>:</label>
                    <select name="searchstatus" id="searchstatus">
                        <option value="0" <?php if($searchData['searchstatus']==0){echo 'selected';}?>><?=$this->lang->line("Realtime Record")?>
                        <option value="1" <?php if($searchData['searchstatus']==1){echo 'selected';}?>><?=$this->lang->line("History Record")?>
                    </select>
                    <select name="sales" id="sales">
                        <option value="0" <?php if($searchData['salesid']==0){echo 'selected';}?>>-<?=$this->lang->line("Salesman")?>-
                        <?php foreach ($salesman as $key => $value) {?>
                            <option value="<?=$value['id']?>" <?php if($searchData['salesid']==$value['id']){echo 'selected';}?>><?=$value['username']?>
                        <?php }?>
                    </select>
                    <select name="officer" id="officer">
                        <option value="0" <?php if($searchData['officerid']==0){echo 'selected';}?>>-<?=$this->lang->line("Interviewer")?>-
                        <?php foreach ($officer as $key => $value) {?>
                            <option value="<?=$value['id']?>" <?php if($searchData['officerid']==$value['id']){echo 'selected';}?>><?=$value['name']?>
                        <?php }?>
                    </select>
                    <select name="status" id="status">
                        <option value="-1" <?php if($searchData['status']==-1){echo 'selected';}?>>-<?=$this->lang->line("Status")?>-
                        <option value="0" <?php if($searchData['status']==0){echo 'selected';}?>><?=$status[0]?>
                        <option value="1" <?php if($searchData['status']==1){echo 'selected';}?>><?=$status[1]?>
                        <option value="2" <?php if($searchData['status']==2){echo 'selected';}?>><?=$status[2]?>
                        <option value="6" <?php if($searchData['status']==6){echo 'selected';}?>><?=$status[6]?>
                        <option value="3" <?php if($searchData['status']==3){echo 'selected';}?>><?=$status[3]?>
                        <option value="4" <?php if($searchData['status']==4){echo 'selected';}?>><?=$status[4]?>
                        <option value="7" <?php if($searchData['status']==7){echo 'selected';}?>><?=$status[7]?>
                        <option value="8" <?php if($searchData['status']==8){echo 'selected';}?>><?=$status[8]?>
                        <option value="5" <?php if($searchData['status']==5){echo 'selected';}?>><?=$status[5]?>
                    </select>
                    <select name="passtype" id="passtype">
                        <option value="0" <?php if($searchData['passtype']==0){echo 'selected';}?>>-<?=$this->lang->line("Permittype")?>-
                        <option value="1" <?php if($searchData['passtype']==1){echo 'selected';}?>>WP
                        <option value="2" <?php if($searchData['passtype']==2){echo 'selected';}?>>SP
                        <option value="3" <?php if($searchData['passtype']==3){echo 'selected';}?>>EP
                    </select>          
                    <label>Total <?=$total?> Records</label>
                </td>
            </tr>
            <tr>
                <td>
                    <label><?=$this->lang->line("Date")?>:</label>
                    <input type="text" name="starttime" id="starttime" style="width:80px;" value="<?=$searchData['starttime']==""?"":$searchData['starttime']?>" placeholder="<?=$this->lang->line("start")?>" />
                    -
                    <input type="text" name="endtime" id="endtime" style="width:80px;" value="<?=$searchData['endtime']==""?"":$searchData['endtime']?>" placeholder="<?=$this->lang->line("end")?>" />
                    <input type="text" placeholder="<?=$this->lang->line("other key")?>" name="condition" id="condition" value="<?=$searchData['condition']?>"/>
                    <input type="submit" value="<?=$this->lang->line("Search")?>" /> <input type="button" value="<?=$this->lang->line("Reset")?>" class="resett" style="background-image:none;" />
                    <?php if($this->session->userdata('user')->role == 0){?>
                    <a href="#" id="export2excel"  class="button"><?=$this->lang->line("Export2Excel")?></a>
                    <?php }?>
                </td>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <table class="list-table">
            <tr>
                <th><?=$this->lang->line("CompanyName")?></th>
                <th class="order" ordername="w.name"><?=$this->lang->line("Worker Name")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th class="order" ordername="o.worktype"><?=$this->lang->line("Permittype")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th class="order" ordername="p.status"><?=$this->lang->line("Status")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th class="order" ordername="p.arrivedtime">
                    <?php if($searchData['status']==1){
                        echo $this->lang->line('Application Date');
                    }else if($searchData['status']==2){
                        echo $this->lang->line('Approve Date');
                    }else if($searchData['status']==3){
                        echo $this->lang->line('Arrived Date');
                    }else if($searchData['status']==4){
                        echo $this->lang->line('Issue Date');
                    }else if($searchData['status']==5){
                        echo $this->lang->line('Return Date');
                    }else if($searchData['status']==6){
                        echo $this->lang->line('Rejected Date');
                    }else if($searchData['status']==7){
                        echo $this->lang->line('Appointment Date');
                    }else if($searchData['status']==8){
                        echo $this->lang->line('Cancel Date');
                    }else{
                        echo $this->lang->line('Create Date');
                    }?>
                    <img src="<?=base_url()?>resource/img/arrow_no.png" />
                </th>
                <th>MI</th>
                <th>WICI</th>
                <th class="order" ordername="u.username"><?=$this->lang->line("Salesman")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th class="order" ordername="e.name"><?=$this->lang->line("Interviewer")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
            </tr>
            <?php foreach ($summary as $key => $value) {?>
            <tr>
                <td style="text-align:left;">&nbsp;<?=$value['name']?></td>
                <td><?=$value['workname']?></td>
                <td><?=(isset($value['worktype']))?$passtype[$value['worktype']]:''?></td>
                <td><?=$status[$value['status']]?></td>
                <td>
                    <?php if($searchData['status']==1){
                        if($value['applytime'] != NULL&&$value['applytime'] != ''){echo date('Y-m-d H:m:s',$value['applytime']);}else{echo '';};
                    }else if($searchData['status']==2){
                        if($value['approvetime'] != NULL&&$value['approvetime'] != ''){echo date('Y-m-d H:m:s',$value['approvetime']);}else{echo '';};
                    }else if($searchData['status']==3){
                        if($value['arrivedtime'] != NULL&&$value['arrivedtime'] != ''){echo date('Y-m-d H:m:s',$value['arrivedtime']);}else{echo '';};
                    }else if($searchData['status']==4){
                        if($value['issuetime'] != NULL&&$value['issuetime'] != ''){echo date('Y-m-d H:m:s',$value['issuetime']);}else{echo '';};
                    }else if($searchData['status']==5){
                        if($value['returntime'] != NULL&&$value['returntime'] != ''){echo date('Y-m-d H:m:s',$value['returntime']);}else{echo '';};
                    }else if($searchData['status']==6){
                        if($value['rejectedtime'] != NULL&&$value['rejectedtime'] != ''){echo date('Y-m-d H:m:s',$value['rejectedtime']);}else{echo '';};
                    }else if($searchData['status']==7){
                        if($value['othertime'] != NULL&&$value['othertime'] != ''){echo date('Y-m-d H:m:s',$value['othertime']);}else{echo '';};
                    }else if($searchData['status']==8){
                        if($value['canceldate'] != NULL&&$value['canceldate'] != ''){echo date('Y-m-d H:m:s',$value['canceldate']);}else{echo '';};
                    }else{
                        if($value['createtime'] != NULL&&$value['createtime'] != ''){echo date('Y-m-d H:m:s',$value['createtime']);}else{echo '';};
                    }?>
                </td>
                <td><?php if($value['status']*1>3){
                        echo $value['wi']==0?'Y(R)':($value['wi']==1?'Y(B)':'N');
                    }?>
                </td>
                <td>
                    <?php if($value['status']*1>3){
                        echo $value['wici']==0?'Y(R)':($value['wici']==1?'Y(B)':'N');
                    }?>
                </td>
                <td><?=$value['username']?></td>
                <td><?=$value['employeename']?></td>
            </tr>
            <?php }
            if(count($summary) == 0){?>
            <tr>
                <td colspan="5">
                    NO DATA
                </td>
            </tr>
            <?php }?>
            <tr>
                <td colspan="5" class="pagination">
                    <?php echo $page;?>
                </td>
            </tr>
        </table>
    </div>
</div>
<script>

var url = '<?=base_url()?>profile/index';
var order = "<?=$searchData['ordername']?>";
var orders = order.split(" ");
$("th").each(function(){
    var ordername = $(this).attr("ordername");
    if(orders[0] == ordername){
        $(this).children("img").attr("src","<?=base_url()?>resource/img/arrow_"+orders[1]+".png");
    }
});

$('#starttime').datetimepicker({
    format:"Y-m-d",      //格式化日期
    timepicker:false,    //关闭时间选项
});

$('#endtime').datetimepicker({
    format:"Y-m-d",      //格式化日期
    timepicker:false,    //关闭时间选项
});

$(".resett").click(function(){
    $("#sales").val(0);
    $("#status").val(0);
    $("#passtype").val(0);
    $("#starttime").val("");
    $("#endtime").val("");
    $("#condition").val("");
});
$("#export2excel").click(function(){
    
    var url = "<?=base_url()?>reminder/export2excel?";
    var data = $("#myform").serialize();
    location.href = url+data;
});
</script>
